# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=spyder
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=5.4.1
pkgrel=1
pkgdesc='The Scientific Python Development Environment (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('spdx:MIT')
url='https://github.com/spyder-ide/spyder'
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-atomicwrites
    ${MINGW_PACKAGE_PREFIX}-python-chardet
    ${MINGW_PACKAGE_PREFIX}-python-cloudpickle
    ${MINGW_PACKAGE_PREFIX}-python-cookiecutter
    ${MINGW_PACKAGE_PREFIX}-python-diff-match-patch
    ${MINGW_PACKAGE_PREFIX}-python-intervaltree
    ${MINGW_PACKAGE_PREFIX}-python-ipython
    ${MINGW_PACKAGE_PREFIX}-python-jedi
    ${MINGW_PACKAGE_PREFIX}-python-jellyfish
    ${MINGW_PACKAGE_PREFIX}-python-jsonschema
    ${MINGW_PACKAGE_PREFIX}-python-keyring
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-numpydoc
    ${MINGW_PACKAGE_PREFIX}-python-paramiko
    ${MINGW_PACKAGE_PREFIX}-python-parso
    ${MINGW_PACKAGE_PREFIX}-python-pexpect
    ${MINGW_PACKAGE_PREFIX}-python-pickleshare
    ${MINGW_PACKAGE_PREFIX}-python-psutil
    ${MINGW_PACKAGE_PREFIX}-python-pygments
    ${MINGW_PACKAGE_PREFIX}-python-pylint
    ${MINGW_PACKAGE_PREFIX}-python-pylint-venv
    ${MINGW_PACKAGE_PREFIX}-python-lsp-black
    ${MINGW_PACKAGE_PREFIX}-python-pyls-spyder
    ${MINGW_PACKAGE_PREFIX}-python-pyqt5
    ${MINGW_PACKAGE_PREFIX}-python-lsp-server
    ${MINGW_PACKAGE_PREFIX}-python-pyzmq
    ${MINGW_PACKAGE_PREFIX}-python-qdarkstyle
    ${MINGW_PACKAGE_PREFIX}-python-qstylizer
    ${MINGW_PACKAGE_PREFIX}-python-qtawesome
    ${MINGW_PACKAGE_PREFIX}-python-qtconsole
    ${MINGW_PACKAGE_PREFIX}-python-qtpy
    ${MINGW_PACKAGE_PREFIX}-python-rtree
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-python-sphinx
    ${MINGW_PACKAGE_PREFIX}-python-spyder-kernels
    ${MINGW_PACKAGE_PREFIX}-python-textdistance
    ${MINGW_PACKAGE_PREFIX}-python-three-merge
    ${MINGW_PACKAGE_PREFIX}-python-watchdog
    ${MINGW_PACKAGE_PREFIX}-qtwebkit
)
optdepends=(
    ${MINGW_PACKAGE_PREFIX}-cython
    ${MINGW_PACKAGE_PREFIX}-python-matplotlib
    ${MINGW_PACKAGE_PREFIX}-python-numpy
    ${MINGW_PACKAGE_PREFIX}-python-pandas
    ${MINGW_PACKAGE_PREFIX}-python-scipy
)
makedepends=(${MINGW_PACKAGE_PREFIX}-python-setuptools)
options=(!strip)
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        spyder-requirements-fix.patch)
sha256sums=('91004e6115e18f3f8e424ed59716ff50a8838bdda603c89a96c150f90cea8651'
            '7268eae8700e6a1f0046af26f047f119c2d3dce07be2e5b0f5d97d294b0f0292')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/spyder-requirements-fix.patch

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py*; do
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
